<template>
    <div>
        {{catelist}}
        <van-field label="名称" placeholder="请输入名称" v-model="name" />
        <van-field label="参数" placeholder="请输入参数" v-model="params"/>
        选择分类
            <reply :data='catelist' />
        <br>
        <van-button @click="add">添加</van-button>
            
    </div>
</template>

<script>
import reply from'./reply.vue'
    export default {
        name:'cates',
        components:{
            'reply':reply
        },
        data() {
            return {
                name:'',
                params:'',
                pid:0,
                catelist:[]
            }
        },
        methods: {
            add(){
                if(localStorage.getItem('pid')){
                    this.pid = localStorage.getItem('pid')
                }
                let data = {'name':this.name,'pid':this.pid,'params':JSON.stringify(this.params)}
                
                this.$axios.post('/course/cates/',data).then(res=>{
                    localStorage.removeItem('pid','')
                    this.getcatelist()
                })
            },
            getcatelist(){
                this.$axios.get('/course/cates/').then(res=>{
                    this.catelist = {'pid':0,'name':'顶级父类','son':res.data.list}
                })
            }
        },
        mounted() {
            this.getcatelist()
        },
    }
</script>

<style scoped>

</style>